var  clickState = true;
$(function(){
	$("#save-button").click(function(){
		var refundId=$(".layui-form").attr("data-refundId");
		if(refundId.length==0){
			layer.msg("售后单不存在！");
			return false;
		}
		var detailInfos="";
		var detail_tr =$(".refund-detail-info");
		if(detail_tr.length == 0){
			layer.msg("售后信息异常");
			return false;
		}
		for(i=0;i<detail_tr.length;i++){
			var detailId=$(detail_tr[i]).attr("data-id");
			var signQuantity=$(detail_tr[i]).find(".sign-quantity").val();
			var quantity=$(detail_tr[i]).find(".sign-quantity").attr("data-quantity");
			if(!isNum(signQuantity)){
				$(detail_tr[i]).find(".sign-quantity").val("");
				$(detail_tr[i]).find(".sign-quantity").focus();
				layer.msg("请输入正整数");
				return false;
			}else if((Number(quantity)-Number(signQuantity))<0){
				$(detail_tr[i]).find(".sign-quantity").val("");
				$(detail_tr[i]).find(".sign-quantity").focus();
				layer.msg("收货数不能大于退货数");
				return false;
			}
			detailInfos+=detailId+","+signQuantity+";"
		}
		
		var signData ={
			"refundId":refundId,
			"refundInfos":detailInfos
		}
		if(clickState){
			clickState = false;
			$.ajax({
				url:basePath+"/refund/saveSignInfo.shtml",
				data:signData,
				type:"post",
				dataType:"JSON",
				success:ajaxSuccessCloseFun
			});
		}
	});
	$("#close-button").click(function(){
		parent.closeLayer(0);
	});
	$(".sign-quantity").keyup(function(){
		var quantity = $(this).attr("data-quantity");
		var sign = $(this).val();
		var str="";
		if(!isNum(sign)){
			str="请输入正整数";
			$(this).val("");
			$(this).focus();
		}else if((Number(quantity)-Number(sign))<0){
			str="收货数不能大于退货数";
			$(this).val("");
			$(this).focus();
		}
		$(this).parent().parent().find(".layui-word-aux").html(str);
		
	});
});
